package exam.alibaba;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/20 19:49
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int []nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        Arrays.sort(nums);
        int count = 2;
        long ans = 0;
        while (count <= nums.length){
            int num2 = 0,num3 = 0;
            int l = 0;
            for (int i = 0; i < nums.length; i++) {
                if(nums[i] == 2)
                    num2 ++;
                else
                    num3++;
                if(i < count - 1){
                    continue;
                }
                if(num2 == 0)
                    ans+= num3 + 1;
                else if(num3 == 0)
                    ans += num2 + 1;
                else
                    ans += (long) (num2 + 1) * (num3 + 1);
                if(nums[l] == 2 )
                    num2--;
                else
                    num3--;
                l++;
            }
            count++;
        }

        System.out.println(ans);
    }
}
